/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inputjadwal;

import inputjadwal.entity.Pelajar;
import inputjadwal.entity.service.InputJadwalService;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author Andry
 */
public class Main {
    
    private static ApplicationContext appCtx;
    private static InputJadwalService service;
    
    public static void main(String[] args) throws IOException {
         appCtx = new ClassPathXmlApplicationContext("classpath:/inputjadwal/entity/config/ApplicationContext.xml");
         service = (InputJadwalService) appCtx.getBean("appService");
         
        inputPelajar();    
        viewPelajar();
    }
    
    
    private static  void inputPelajar() throws IOException{
        Pelajar pel = new Pelajar();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("MENU INPUT DATA PELAJAR");       
        System.out.print("Masukan Nama pelajar : \t");
        pel.setNama(br.readLine());
        System.out.print("Masukan Nim pelajar : \t");
        pel.setNim(br.readLine());
        System.out.print("Masukan tingkat pelajar : \t");
        pel.setTingkat(Integer.parseInt(br.readLine()));
        System.out.println("Data telah tersimpan");
        service.savePelajar(pel);
    }
    
    private static void viewPelajar(){
        List<Pelajar> listpel = service.findAllPelajar();
        System.out.println("ID\tNIM\tNAMA\tTINGKAT");
        for(Pelajar pelajar : listpel){
            System.out.println(pelajar.getId()+"\t"+pelajar.getNim()+"\t"+pelajar.getNama()+"\t"+pelajar.getTingkat());
        }
        
        
    }
}
